using System;
using System.Drawing;
using System.Collections.Generic;
using System.Text;

 
    public class Punto
    {
        public double X;
        public double Y;


        public Punto(String x, String y)
        {
            X = double.Parse(x);
            Y = double.Parse(y);
        }

        public Punto(double x, double y)
        {
            X = x;
            Y = y;
        }
    }

    public class GPolygon
    {
        private readonly List<Punto> _vertices = new List<Punto>();

        public GPolygon( )
        { 
        }

        public GPolygon(List<Punto> vertices)
        {
            _vertices = vertices;
        }
        public bool pointInPolygon(string lat, string lon)
        {
            if (lat != "" && lon != "")
            {
                Punto point = new Punto(lat, lon);
                return pointInPolygon(point);
            }
            return false;
        }

        public bool pointInPolygon(Punto point)
        {
            int j = _vertices.Count - 1;
            bool oddNodes = false;

            for (int i = 0; i < _vertices.Count; i++)
            {
                if (_vertices[i].Y < point.Y && _vertices[j].Y >= point.Y ||
                    _vertices[j].Y < point.Y && _vertices[i].Y >= point.Y)
                {
                    if (_vertices[i].X +
                        (point.Y - _vertices[i].Y) / (_vertices[j].Y - _vertices[i].Y) * (_vertices[j].X - _vertices[i].X) < point.X)
                    {
                        oddNodes = !oddNodes;
                    }
                }
                j = i;
            }

            return oddNodes;
        }

        public void parseString(string cadena)
        {
            Punto punto = null;
            string[] arraylatlon = cadena.Split('@');
            foreach (string latlon in arraylatlon) {
                 string[] arrayPunto = latlon.Split('|');
                 if (arrayPunto.Length > 1 && arrayPunto[0] != "" && arrayPunto[1] != "")
                 {
                     punto = new Punto(arrayPunto[0], arrayPunto[1]);
                     _vertices.Add(punto);
                 }
            } 
        }
    }
 